<template>
  <el-dialog v-model="dialogVisible" :destroy-on-close="true" :align-center="true" width="50%" title="岗位审核`">
    <el-form :model="dialogData.itemInfo" label-width="100px" label-suffix=" :">
      <div class="audit-wrapper">
        <div class="left-box">
          <el-button type="success" :icon="Check" class="true_btn" @click="handleAuditP">审核通过</el-button>
        </div>
        <div class="right-box">
          <el-input
            class="info-item"
            v-model="dialogData.itemInfo.refuseCtn"
            :rows="3"
            type="textarea"
            placeholder="请填写审核备注信息"
          ></el-input>

          <el-button type="danger" :icon="Close" class="false_btn" @click="handleAuditF">审核拒绝</el-button>
        </div>
      </div>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { OptEnum } from "@/biz/eenum/appEnum";
import { DialogParam } from "@/biz/interface/DialogType";
import { reactive, ref } from "vue";
import { Close, Check } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import { auditJobPassByDealer, auditJobFailedByDealer } from "@/api/modules/dealer/auditjob";
//页面的数据
interface JobDialogOption extends DialogParam {
  //弹出表单的标题
  title: string;

  //当前的数据对象
  itemInfo: { id: string; refuseCtn: string };
}
//弹出框的参数
const dialogVisible = ref(false);
//当前表单数据在这里初始化
const dialogData = reactive<JobDialogOption>({
  optType: OptEnum.UNKNOW,
  title: "",
  itemInfo: {
    id: "",
    refuseCtn: ""
  }
});

//初始化页面的数据
const initItemInfo = (): void => {
  dialogData.itemInfo = {
    id: "",
    refuseCtn: ""
  };
};
// 接收父组件传过来的参数
const acceptParams = (params: DialogParam): void => {
  dialogData.optType = params.optType;
  dialogData.rowData = params.rowData;

  initItemInfo();
  if (dialogData.rowData) {
    dialogData.itemInfo.id = dialogData.rowData.id;
  }

  dialogVisible.value = true;
};
// 审核通过
const handleAuditP = async () => {
  if (dialogData.itemInfo.id) {
    await auditJobPassByDealer({
      id: dialogData.itemInfo.id
    }).then(res => {
      if (res.data) {
        ElMessage.success("审核通过");
        //刷新列表数据
        emits("refresh-list");
        dialogVisible.value = false;
      }
    });
  }
};
// 审核不通过
const handleAuditF = async () => {
  if (dialogData.itemInfo.id) {
    await auditJobFailedByDealer({
      id: dialogData.itemInfo.id,
      aduitContent: dialogData.itemInfo.refuseCtn || ""
    }).then(res => {
      if (res.data) {
        ElMessage.warning("审核不通过");
        //刷新列表数据
        emits("refresh-list");
        dialogVisible.value = false;
      }
    });
  }
};

//页面事件
const emits = defineEmits(["refresh-list"]);

//页面参数
defineExpose({
  acceptParams
});
</script>

<style scoped lang="scss">
.audit-wrapper {
  display: flex;
  justify-content: space-around;
  align-items: center;

  width: 100%;
  height: 100%;

  .left-box {
    // border: 1px solid red;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;

    .true_btn {
      width: 80%;
      height: 118px;
      font-size: 1.8rem;
      margin-top: 10px;
    }
  }
  .right-box {
    // border: 1px solid red;
    width: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;

    .info-item {
      // border: 1px solid red;
      width: 100%;
      margin: 10px;
    }

    .false_btn {
      width: 100%;
    }
  }
}
</style>
